#include "AnimNode_Demo.h"

FMotionMatchingStruct::FMotionMatchingStruct()
{
	
}

void FMotionMatchingStruct::Initialize_AnyThread(const FAnimationInitializeContext& Context)
{
	Super::Initialize_AnyThread(Context);
	PlayValue = 0;
	for (FName val : Names.name)
	{
		CurveValues.Add(0.0);
		CurveNames.Add(val);
		UE_LOG(LogTemp, Warning, TEXT("FMotionMatchingStruct CurveNames:%s"), *val.ToString());
	}
	UE_LOG(LogTemp, Warning, TEXT("FMotionMatchingStruct CurveNames length:%d"), Names.name.Num());
}

void FMotionMatchingStruct::Update_AnyThread(const FAnimationUpdateContext& Context)
{
	Super::Update_AnyThread(Context);
	//取出播放一帧数据
	if(FaceData.test.Num() > 0)
	{
		const int FaceDataNum = FaceData.test.Num();
        if(FaceDataNum > PlayValue)
        {
        	//UE_LOG(LogTemp, Warning, TEXT("FMotionMatchingStruct FaceDataNum length:%d , PlayValue :%d"), FaceDataNum,PlayValue);
        	TArray<FString> facedata_strings = FaceData.test[PlayValue].test;//获取一帧的数据
        	for(int i=0; i<CurveNames.Num(); i++)
        	{
        		const int num = Names.data_num[i];//找出这个形态键对应着数据的第几个索引
        		if(facedata_strings.Num() > num)
        		{
        			UE_LOG(LogTemp, Warning, TEXT("FMotionMatchingStruct facedata_strings:%s"), *facedata_strings[num]);
        			CurveValues[i] = FMath::Clamp(FCString::Atof(*facedata_strings[num]),0.0f,1.0f);
        		}
        	}
        }
        else
        {
        	PlayValue = 0;
        }
        PlayValue++;
	}
	
}